#问题管理页面
from time import sleep
from common.Untils import WJDriver
from selenium.webdriver.common.by import By

class WJRepoTemplate:
    url = ""
    driver = ""

    def __init__(self):
        #WJLogin.WJLogin().LoginSuccess()
        self.url = "http://8.155.1.153:8081/repo/template"
        self.driver = WJDriver.driver
        self.driver.get(self.url)
        WJDriver.Login()
        #点击问题管理
        self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/aside/div/div[1]/ul/li[4]/div/span/div/span[2]").click()
        self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/aside/div/div[1]/ul/li[4]/ul/li[2]").click()
    # 进行页面元素的查找检查
    def TestByRepoTemplate(self):
        sleep(1)
        # 检查类型输入框
        self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[1]/div/div/div[2]/div/div/div/div/span[1]/input").click()
        self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[1]/div/div/div[2]/div/div/div/div/span[1]/input").click()
        print("问题管理页面：类型输入框正常")
        sleep(1)
        # 检查题型输入框
        self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[2]/div/div/div[2]/div/div/div/div/span[1]/input").click()
        self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[2]/div/div/div[2]/div/div/div/div/span[1]/input").click()
        print("问题管理页面：题型输入框正常")
        sleep(1)
        # 检查重置
        self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[5]/div/div/div[2]/div/div/div/div[1]/div/div[1]/button/span").click()
        #assert text == "重置"
        print("问题管理页面：重置")
        # 检查查询
        sleep(1)
        self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[5]/div/div/div[2]/div/div/div/div[1]/div/div[2]/button/span").click()
        #assert text == "查询"
        print("问题管理页面：查询")
        # 检查试题列表
        text = self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[1]/div/div[1]/div").text
        assert text == "试题列表"
        print("问题管理页面：试题列表")
        # 检查序号
        text = self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div/div/div/div/table/thead/tr/th[2]").text
        assert text == "序号"
        print("问题管理页面：序号")
        # 检查类型
        text = self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div/div/div/div/table/thead/tr/th[3]").text
        assert text == "类型"
        print("问题管理页面：类型")
        # 检查题型
        text = self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div/div/div/div/table/thead/tr/th[4]").text
        assert text == "题型"
        print("问题管理页面：题型")
        # 检查名称
        text = self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div/div/div/div/table/thead/tr/th[5]").text
        assert text == "名称"
        print("问题管理页面：名称")
        # 检查答案
        text = self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div/div/div/div/table/thead/tr/th[6]").text
        assert text == "答案"
        print("问题管理页面：答案")
        # 检查操作
        text = self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div/div/div/div/table/thead/tr/th[10]").text
        assert text == "操作"
        print("问题管理页面：操作")
        print("问题管理页面元素正常........")

#         self.driver.quit()
# repoTemplate=WJRepoTemplate()
# repoTemplate.TestByRepoTemplate()